package com.ynny.student.systemDB;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.beans.Transient;

@Component("courseManage")
public class CourseManageImpl implements CourseManage {
@Autowired
private JdbcTemplate jdbcTemplate;
    @Override
    public void updateCourse(String courseName) {
        String sql = "update course set" + courseName + "=" + courseName + "-1";
        int num = jdbcTemplate.update(sql);
        if (num <= 0){
            System.out.println("更新待选课程记录失败");
        }
    }

    @Override
    public void queryCourse() {
        String sql ="select * from course";
        RowMapper<Course> rowMapper;
        rowMapper = new BeanPropertyRowMapper<Course>(Course.class);
        Course course = jdbcTemplate.queryForObject(sql, rowMapper);
        System.out.println(course);
    }
    @Override
    @Transactional(propagation = Propagation.REQUIRED,readOnly = false,
    isolation = Isolation.DEFAULT)

    public void selectCourse(String number, String courseName) {
        updateCourse(courseName);
        queryCourse();

        jdbcTemplate.execute("create table if not exists optional_courses("
        + "number varchar(20),courseName varchar(20),score double)");

        String sql = "insert";




    }
}
